# -*- coding: utf-8 -*-
from datetime import timedelta
from jms_predict_route.dim.dim_yl_tmsnew_tms_vehicle_line_base_dt import jms_dim__dim_yl_tmsnew_tms_vehicle_line_base_dt
from jms_predict_route.dim.dim_yl_tmsnew_tms_vehicle_point_base_dt import jms_dim__dim_yl_tmsnew_tms_vehicle_point_base_dt
from jms_predict_route.dim.dim_yl_tmsnew_tms_transfer_shift_base_dt import jms_dim__dim_yl_tmsnew_tms_transfer_shift_base_dt
from jms_predict_route.dim.dim_yl_tms_route_predict_base_dt import jms_dim__dim_yl_tms_route_predict_base_dt
from jms_predict_route.dim.dim_yl_tms_branch_time_shift_base_dt import jms_dim__dim_yl_tms_branch_time_shift_base_dt
from jms_predict_route.dim.dim_tab_rou_competitor_effective import jms_dim__dim_tab_rou_competitor_effective
from jms_predict_route.dim.dim_tms_main_delivery_network_base_dt import jms_dim__dim_tms_main_delivery_network_base_dt
from jms_predict_route.dim.dim_tms_airport_line_base_dt import jms_dim__dim_tms_airport_line_base_dt
from jms_predict_route.dim.dim_tms_airport_point_base_dt import jms_dim__dim_tms_airport_point_base_dt

from utils.operators.spark_submit import SparkSubmitOperator
jms_dm__dm_predict_route_dt = SparkSubmitOperator(
    conn_id='spark_route',
    task_id='jms_dm__dm_predict_route_dt',
    pool_slots=2,
    email=['zhangqinglin@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_predict_route_dt_{{ execution_date | cst_hour}}',
    driver_memory='4G' , 
    executor_memory='3G' , 
    executor_cores=4 , 
    num_executors=10 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 12 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G'  
          },
    jars='hdfs:///route/package/graphframes-0.7.0-spark2.3-s_2.11.jar,hdfs:///route/package/common-1.0-SNAPSHOT.jar',
    java_class='com.yunlu.bigdata.jobs.route.export.PredictRoute',
    application='hdfs:///route/package/predict_route/original-jobs-1.0-SNAPSHOT.jar',
    application_args=['{{ execution_date | cst_ds }}'],
    execution_timeout=timedelta(hours=1)
)

jms_dm__dm_predict_route_dt <<[jms_dim__dim_yl_tms_branch_time_shift_base_dt,
                               jms_dim__dim_tab_rou_competitor_effective,
                               jms_dim__dim_yl_tms_route_predict_base_dt,
                               jms_dim__dim_yl_tmsnew_tms_vehicle_line_base_dt,
                               jms_dim__dim_tms_main_delivery_network_base_dt,
                               jms_dim__dim_yl_tmsnew_tms_vehicle_point_base_dt,
                               jms_dim__dim_yl_tmsnew_tms_transfer_shift_base_dt,
                               jms_dim__dim_tms_airport_line_base_dt,
                               jms_dim__dim_tms_airport_point_base_dt,]
